<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FormLayout 表单布局</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<script src="__PUBLIC__/scripts/boot.js" type="text/javascript"></script>

<style type="text/css">

</style>

</head>
<body>
<h1>项目投资保护条款</h1>
<div style="width: 900px;">
<div class="mini-toolbar" style="padding: 2px;">
<table style="width: 100%;">
	<tr>
		<td style="width: 100%;"><span>项目名称: {$_SESSION['pname']}</span>
		&nbsp <span>项目经理: {$_SESSION['managername']}</span></td>
		<td style="white-space: nowrap;"></td>
	</tr>
</table>
</div>
</div>
<div style="width: 900px;">
<div class="mini-toolbar" style="border-bottom: 0; padding: 2px;">
<table style="width: 100%;">
	<tr>
		<td style="width: 100%;"><a class="mini-button"
			iconCls="icon-add" onclick="showWindow()">修改</a></td>
		<td style="white-space: nowrap;"></td>
	</tr>
</table>
</div>
</div>

<div id="form0" style="width: 904px;">
<fieldset>

<table>
	<tr id="tr_type">
		<td class="td1"><label for="type">保护条款类型 </label></td>
		<td id="label_type1">{$list["type"]}</td>
	</tr>
</table>
</fieldset>

<fieldset><legend> 条款内容说明 </legend>
<table>
	<tr>
		<td class="td1"><label id="label_condition0" for="condition">触发条件
		</label></td>
		<td><label id="label_condition1">{$list["condition"]}</label></td>
	</tr>
	<tr>
		<td class="td1"><label id="label_content0" for="content">说明
		</label></td>
		<td id="label_content1">{$list["content"]}</td>
	</tr>
	<tr>
		<td class="td1"><label id="label_detailcontent0"
			for="detailcontent">详细说明 </label></td>
		<td id="label_detailcontent1">{$list["detailcontent"]}</td>
	</tr>

</table>

</fieldset>
</div>

<div id="win1" class="mini-window" title="详细内容" style="width: 800px;"
	showMaxButton="true" showToolbar="true" showFooter="true"
	showModal="true" allowResize="true" allowDrag="true">
<div id="form1">
<fieldset>

<table>
	<tr id="tr_type">
		<td class="td1"><label for="type">保护条款类型 </label></td>
		<td><input class="mini-combobox" id="type" name="type"
			onvaluechanged="typechange()" url="__PUBLIC__/data/addtype.txt"
			value="" textField="text" valueField="id" /></td>
	</tr>
</table>
</fieldset>

<fieldset><legend> 条款内容说明 </legend>
<table>
	<tr>
		<td class="td1"><label id="label_condition" for="condition">触发条件
		</label></td>
		<td><input class="mini-textbox" id="condition" type="text" width="600px"
			name="condition" /></td>
	</tr>
	<tr>
		<td class="td1"><label id="label_content" for="content">说明
		</label></td>
		<td><input class="mini-textarea" id="content" type="text" width="600px"
			name="content" /></td>
	</tr>
	<tr>
		<td class="td1"><label id="label_detailcontent"
			for="detailcontent">详细说明 </label></td>
		<td><input class="mini-textarea" id="detailcontent" type="text" width="600px"
			name="detailcontent" /></td>
	</tr>

</table>

</fieldset>

<br />
<a class="mini-button" iconCls="icon-save" plain="true"
	onclick="updateForm()">更新</a> <a class="mini-button"
	iconCls="icon-redo" plain="true" onclick="loadForm()()">还原</a></div>
</div>
<script type="text/javascript">
	mini.parse();
	var olddata;
	loadForm();

	function updateForm() {
		//提交表单数据
		if (checkauth()) {
			var form = new mini.Form("#form1");
			var data = form.getData(); //获取表单多个控件的数据
			//var json = mini.encode(data);   //序列化成JSON
			$.ajax({
				url : "__APP__/Post/post_2_update",
				type : "post",
				data : {
					Data : data
				},
				success : function(text) {
					mini.alert("提交成功!");
					var obj = JSON.parse(text);

					$("#label_condition1").html(obj.condition);
					$("#label_content1").html(obj.content);
					$("#label_type1").html(obj.type);
					$("#label_detailcontent1").html(obj.detailcontent);
					olddata = form.getData();
				}
			});
		}
	}
	function loadForm() {
		//加载表单数据
		var form = new mini.Form("#form1");
		var form0 = new mini.Form("#form0");

		//var pid = document.getElementById("pid").value;
		//mini.alert(pid);
		$.ajax({
			url : "__APP__/Post/post_2",
			type : "post",
			success : function(text) {
				var data = mini.decode(text);

				//反序列化成对象
				if (data['error'])
					mini.alert("尚未选择项目！", "提示", function() {
						window.CloseOwnerWindow('refresh');
					});
				form.setData(data);
				form0.setData(data);
				typechange(); //设置多个控件数据
				olddata = form.getData();
			}
		});
	}
	function getForm() {
		//提交表单数据
		var form = new mini.Form("#form1");
		form.validate();
		if (form.isValid() == false)
			return;

		var data = form.getData(); //获取表单多个控件的数据
		var json = mini.encode(data); //序列化成JSON
		mini.alert(json);
	}

	function resetForm() {
		var form = new mini.Form("#form1");
		form.reset();
	}

	function typechange() {
		var obj = mini.get("type");
		var val = obj.getText();

		switch (val) {
		case ("回购"):

			$("#label_content").html("回购利率（单利）");
			$("#label_content0").html("回购利率（单利）");
			break;
		case ("股份调整"):
			$("#label_content").html("调整比率");
			$("#label_content0").html("调整比率");
			break;
		case ("现金补偿"):
			$("#label_content").html("金额和比率");
			$("#label_content0").html("金额和比率");
			break;
		case ("其他"):
			$("#label_content").html("说明");
			$("#label_content0").html("说明");
			break;
		default:
			;
		}
	}

	function showWindow() {
		var win = mini.get("win1");
		win.show();
	}
	function getData() {
		var form = new mini.Form("#form1");
		var data = form.getData();
		var json1 = mini.encode(data);
		//alert(json1);
		var json2 = mini.encode(olddata);
		// alert(json2);
		if (json2 == "null"
				&& json1 == '{"type":"","condition":"","content":"","detailcontent":""}')
			return "无变化";
		if (json1 != json2)
			return "已经改变内容，尚未提交，";
		else
			return "无变化";

	}
	function CloseWindow(action) {

		if (window.CloseOwnerWindow)
			window.CloseOwnerWindow(action);

		else
			window.close();

	}
	function checkauth() {
		var state = "{$_SESSION['state']}";
		if (state == "休眠") {
			mini.alert("项目休眠，需要在基本信息表中激活！");
			return false;
		}
		var uname = "{$_SESSION['nickname']}";
		var mname = "{$_SESSION['membername']}";
		var depart = "{$_SESSION['depart']}";
		var pos = mname.indexOf(uname);
		if (pos == -1 && depart != "营运"
				&& uname != "{$_SESSION['managername']}") {
			mini.alert("无操作权限！");
			return false;
		} else
			return true;
	}
</script>

</body>
</html>